define(function(require,exports,module){
    var Validator = require("../common/validator");
    var myWidGet = require("../common/myWidGet");

    require("../common/dialog");
    var FormValidator = {
        editValidator:function(element){
            var v = new Validator({
                attrs:{
                    itemClass:"test"
                },
                element:element,
                autoSubmit:false,
                onFormValidated:function(err,results,form){
                    /*判断是否有id*/
                    if(!err){
                        var fatherBody = $(window.top.document.body);
                        var self =fatherBody.find("#modal-addIndustry .modal-header label.title").html();
                        var editIndustryForm = fatherBody.find("#editIndustryForm");
                        switch(self){
                            case "编辑行业管理":
                                myWidGet.specialAjax(window.jkconfig.webapiurlv + "typemanage/updateindustry",editIndustryForm, "POST", function (data) {
                                    fatherBody.find("#modal-addIndustry").hide();
                                    if (data.code == 0) {
                                        $.showConfirm(data.msg, function () {
                                           window.location.href = "industryManage.html";
                                        });
                                    } else {
                                        $.showErr(data.msg);
                                    }

                                });
                                break;
                            case "添加行业管理":
                                myWidGet.specialAjax(window.jkconfig.webapiurlv + "typemanage/addindustry", editIndustryForm, "POST", function (data) {
                                    fatherBody.find("#modal-addIndustry").hide();
                                    if (data.code == 0) {
                                        $.showConfirm(data.msg, function () {
                                            window.location.href = "industryManage.html";
                                        });
                                    } else {
                                        $.showErr(data.msg);
                                    }
                                });
                                break;
                        }
                    }
                },
                failSilently: true
            });
            v.addItem({
                element:'[name=sort]',
                required:true,
                display:'序号',
                rule:'normalNumber'
            }).addItem({
                element:'[name=name]',
                required:true,
                display:'行业名称',
                rule:'isSpecialSymbol'
            })
        }
    }
    module.exports = FormValidator;
})



